home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / xarchie-2.0.9 / actions.c < prev    next >
C/C++ Source or Header  |  1995-06-18  |  6KB  |  299 lines

  1. /*
  2.  * actions.c : Widget action procedures
  3.  *
  4.  * Other modules also define actions, and call XtAppAddActions() when
  5.  * they are initialized.
  6.  *
  7.  * George Ferguson, ferguson@cs.rochester.edu, 2 Nov 1991.
  8.  * Version 2.0: 23 Apr 1993.
  9.  * 30 Jun 1993: Use sindex() from support.c rather than strstr(3).
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <X11/Intrinsic.h>
  14. #include "xarchie.h"
  15. #include "browser.h"
  16. #include "types.h"
  17. #include "appres.h"
  18. #include "actions.h"
  19. #include "file-panel.h"
  20. #include "ftp-actions.h"
  21. #include "about.h"
  22. #ifdef HELP
  23. # include "help.h"
  24. #endif
  25. #include "query.h"
  26. #include "regex.h"
  27. #include "xutil.h"
  28. #include "stringdefs.h"
  29. #include "alert.h"
  30. #include "confirm.h"
  31. #include "debug.h"
  32. extern void abortDirsend();        /* dirsend.c */
  33. extern void ftpAbortTransfer();        /* ftp-actions.c */
  34. extern char *sindex();            /* support.c (replaces strstr(3)) */
  35.  
  36. /*
  37.  * Functions defined here
  38.  */
  39. void initActions();
  40.  
  41. static void quitAction();
  42. static void queryAction(),abortAction(),queryOrAbortAction();
  43. static void queryHostAction(),queryLocationAction();
  44. static void shiftDownAction(),shiftUpAction(),shiftTopAction();
  45. static void openAllAction(),openFilesAction(),openDirectoriesAction();
  46. static void getAction();
  47.  
  48. /*
  49.  * Data defined here:
  50.  */
  51. static XtActionsRec actionTable[] = {
  52.     { "quit",            quitAction },
  53.     { "query",            queryAction },
  54.     { "abort",            abortAction },
  55.     { "query-or-abort",        queryOrAbortAction },
  56.     { "query-host",        queryHostAction },
  57.     { "query-location",        queryLocationAction },
  58.     { "browser-down",        shiftDownAction },
  59.     { "browser-up",        shiftUpAction },
  60.     { "browser-top",        shiftTopAction },
  61.     { "browser-open-files",    openFilesAction },
  62.     { "browser-open-directories",    openDirectoriesAction },
  63.     { "browser-open-all",    openAllAction },
  64.     { "ftp-get",        getAction },
  65. };
  66.  
  67. /*    -    -    -    -    -    -    -    -    */
  68.  
  69. void
  70. initActions()
  71. {
  72.     XtAppAddActions(appContext,actionTable,XtNumber(actionTable));
  73.     initFtpActions();
  74.     initFilePanelActions();
  75.     initAboutActions();
  76. #ifdef HELP
  77.     initHelpActions();
  78. #endif
  79. }
  80.  
  81. /*    -    -    -    -    -    -    -    -    */
  82.  
  83. #define ACTION_PROC(NAME)    void NAME(w,event,params,num_params) \
  84.                     Widget w; \
  85.                     XEvent *event; \
  86.                     String *params; \
  87.                     Cardinal *num_params;
  88.  
  89. /*ARGSUSED*/
  90. static
  91. ACTION_PROC(quitAction)
  92. {
  93.     bye(0);
  94. }
  95.  
  96. /*ARGSUSED*/
  97. static
  98. ACTION_PROC(queryAction)
  99. {
  100.     char *s;
  101.     int len;
  102.     Boolean gif;
  103.  
  104.     if (getBrowserState() != BROWSER_READY) {
  105.     /* Don't do anything using popups since we could be in dirsend()
  106.        by now. */
  107.     XBell(display,0);
  108.     return;
  109.     }
  110.     if ((s=getWidgetString(searchText)) == NULL || *s == '\0') {
  111.     alert0("No search term specified.");
  112.     return;
  113.     }
  114. #ifndef DONT_CATCH_GIFS
  115.     len = strlen(s);
  116.     gif = False;
  117.     switch (appResources.searchType) {
  118.     case GfExact:
  119.         gif = ((len > 4 &&
  120.             (!strcmp(s+len-4,".gif") || !strcmp(s+len-4,".GIF"))) ||
  121.            (len > 6 &&
  122.             (!strcmp(s+len-6,".gif.Z") || !strcmp(s+len-6,".GIF.Z"))));
  123.         break;
  124.     case GfSubstr:
  125.     case GfExactSubstr:
  126.     case GfSubcase:
  127.     case GfExactSubcase:
  128.         gif = (sindex(s,"gif") || sindex(s,"GIF"));
  129.         break;
  130.     case GfRegexp:
  131.     case GfExactRegexp:
  132.         gif = (re_comp(s) == NULL &&
  133.            (re_exec("@PrObAbLyNoTaFiLe@.gif") ||
  134.             re_exec("@PrObAbLyNoTaFiLe@.gif.Z")));
  135.         break;
  136.     }
  137.     if (gif) {
  138.     if (!confirm0("Your search term will match GIFs. Do it anyway?"))
  139.         return;
  140.     else if (appResources.niceLevel <= 0 &&
  141.          !confirm0("Really do it without increasing niceness?"))
  142.         return;
  143.     }
  144. #endif /* DONT_CATCH_GIFS */
  145.     /* We're about to do the query, so disable querying */
  146.     setBrowserState(BROWSER_DIRSEND);
  147.     queryItemAndParse(s);
  148.     /* Re-enable querying */
  149.     setBrowserState(BROWSER_READY);
  150. }
  151.  
  152. /*ARGSUSED*/
  153. static
  154. ACTION_PROC(abortAction)
  155. {
  156.     DEBUG0("abortAction...\n");
  157.     XtSetSensitive(abortButton,False);
  158.     switch (getBrowserState()) {
  159.     case BROWSER_DIRSEND:
  160.         abortDirsend();
  161.         break;
  162.     case BROWSER_FTP:
  163.         ftpAbortTransfer();
  164.         break;
  165.     }
  166.     DEBUG0("abortAction: done\n");
  167. }
  168.  
  169. /*ARGSUSED*/
  170. static
  171. ACTION_PROC(queryOrAbortAction)
  172. {
  173.     DEBUG0("queryOrAbortAction...\n");
  174.     if (getBrowserState() == BROWSER_READY)
  175.     XtCallActionProc(toplevel,"query",NULL,NULL,0);
  176.     else
  177.     XtCallActionProc(toplevel,"abort",NULL,NULL,0);
  178.     DEBUG0("queryOrAbortAction: done\n");
  179. }
  180.  
  181. /*ARGSUSED*/
  182. static
  183. ACTION_PROC(queryHostAction)
  184. {
  185.     char *host;
  186.  
  187.     if (getBrowserState() != BROWSER_READY) {
  188.     XBell(display,0);
  189.     return;
  190.     }
  191.     if ((host=getWidgetString(hostText)) == NULL || *host == '\0') {
  192.     alert0("No host specified.");
  193.     return;
  194.     }
  195.     /* We're about to do the query, so disable querying */
  196.     setBrowserState(BROWSER_DIRSEND);
  197.     queryHostAndParse(host);
  198.     /* Re-enable querying */
  199.     setBrowserState(BROWSER_READY);
  200. }
  201.  
  202. /*ARGSUSED*/
  203. static
  204. ACTION_PROC(queryLocationAction)
  205. {
  206.     char *host,*loc;
  207.  
  208.     if (getBrowserState() != BROWSER_READY) {
  209.     XBell(display,0);
  210.     return;
  211.     }
  212.     if ((host=getWidgetString(hostText)) == NULL || *host == '\0') {
  213.     alert0("No host specified.");
  214.     return;
  215.     }
  216.     if ((loc=getWidgetString(locationText)) == NULL || *loc == '\0') {
  217.     alert0("No host specified.");
  218.     return;
  219.     }
  220.     /* We're about to do the query, so disable querying */
  221.     setBrowserState(BROWSER_DIRSEND);
  222.     queryLocationAndParse(host,loc);
  223.     /* Re-enable querying */
  224.     setBrowserState(BROWSER_READY);
  225. }
  226.  
  227. /*    -    -    -    -    -    -    -    -    */
  228.  
  229. /*ARGSUSED*/
  230. static
  231. ACTION_PROC(shiftDownAction)
  232. {
  233.     shiftBrowserDown();
  234. }
  235.  
  236. /*ARGSUSED*/
  237. static
  238. ACTION_PROC(shiftUpAction)
  239. {
  240.     shiftBrowserUp();
  241. }
  242.  
  243. /*ARGSUSED*/
  244. static
  245. ACTION_PROC(shiftTopAction)
  246. {
  247.     shiftBrowserTop();
  248. }
  249.  
  250. /*ARGSUSED*/
  251. static
  252. ACTION_PROC(openAllAction)
  253. {
  254.     if (getBrowserState() != BROWSER_READY) {
  255.     XBell(display,0);
  256.     return;
  257.     }
  258.     if (openBrowserAll() == 1)
  259.     shiftBrowserDown();
  260. }
  261.  
  262. /*ARGSUSED*/
  263. static
  264. ACTION_PROC(openDirectoriesAction)
  265. {
  266.     if (getBrowserState() != BROWSER_READY) {
  267.     XBell(display,0);
  268.     return;
  269.     }
  270.     if (openBrowserDirectories() == 1)
  271.     shiftBrowserDown();
  272. }
  273.  
  274. /*ARGSUSED*/
  275. static
  276. ACTION_PROC(openFilesAction)
  277. {
  278.     if (getBrowserState() != BROWSER_READY) {
  279.     XBell(display,0);
  280.     return;
  281.     }
  282.     openBrowserFiles();
  283. }
  284.  
  285. /*    -    -    -    -    -    -    -    -    */
  286.  
  287. /*ARGSUSED*/
  288. static
  289. ACTION_PROC(getAction)
  290. {
  291.     if (getBrowserState() != BROWSER_READY) {
  292.     XBell(display,0);
  293.     return;
  294.     }
  295.     DEBUG0("getAction...\n");
  296.     ftpGetSelectedItems();
  297.     DEBUG0("getAction: done\n");
  298. }
  299.